home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE02 / RPC10C / RPC10C.ZIP / RPDEMO.ZIP / RPFORM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-04-27  |  10.6 KB  |  378 lines

  1. unit Rpform;
  2.  
  3. interface
  4.  
  5. uses
  6.   Printers,
  7.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  8.   Forms, Dialogs, StdCtrls, Buttons, RPrinter, ExtCtrls;
  9.  
  10. type
  11.   TReportForm = class(TForm)
  12.     Label1: TLabel;
  13.     BitBtn1: TBitBtn;
  14.     TestReportPrinter: TReportPrinter;
  15.     procedure BitBtn1Click(Sender: TObject);
  16.     procedure FormActivate(Sender: TObject);
  17.     procedure TestReportPrinterPrint(Sender: TObject);
  18.     procedure TestReportPrinterBeforePrint(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   ReportForm: TReportForm;
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. procedure TReportForm.BitBtn1Click(Sender: TObject);
  33. begin
  34.   If (BitBtn1.Kind = bkCancel) then begin
  35.     TestReportPrinter.Abort;
  36.   end else begin
  37.     Close;
  38.   end; { else }
  39. end;
  40.  
  41.  
  42. procedure TReportForm.FormActivate(Sender: TObject);
  43.  
  44. var
  45.   I1: integer;
  46.  
  47. begin
  48.   With TestReportPrinter do begin
  49.     Execute;
  50.     BitBtn1.Kind := bkOK;
  51.     If Aborted then begin
  52.       StatusFormat := #13'Report Canceled!';
  53.       UpdateStatus;
  54.     end else begin
  55.       StatusFormat := #13'Report Completed!';
  56.       UpdateStatus;
  57.     end; { else }
  58.   end; { with }
  59. end;
  60.  
  61. procedure TReportForm.TestReportPrinterBeforePrint(Sender: TObject);
  62. begin
  63.   With TestReportPrinter do begin
  64.     StatusFormat := 'Printing Page %p'#13'%0'#13'%1';
  65.     StatusText.Add('');
  66.     StatusText.Add('');
  67.  
  68.   { Test in landscape - works }
  69.   { Orientation := poLandscape; }
  70.  
  71.   { Change paper size - doesn't work }
  72.   { DevMode^.dmPaperSize := 0;
  73.     DevMode^.dmPaperLength := 2159;
  74.     DevMode^.dmPaperWidth := 1270;
  75.     ResetPrinter; }
  76.   end; { with }
  77. end;
  78.  
  79.  
  80. procedure TReportForm.TestReportPrinterPrint(Sender: TObject);
  81.  
  82. var
  83.   I1: integer;
  84.   L1: longint;
  85.   S1: string[20];
  86.   S2: string[20];
  87.   Bitmap: TBitmap;
  88.   PolyLineArr: array[1..6] of TPoint;
  89.  
  90. begin
  91.   With TestReportPrinter do begin
  92.   {*** Report Page Demo ***}
  93.     StatusText[0] := 'Printing Report Page';
  94.     StatusText[1] := 'Boxed columns';
  95.     UpdateStatus;
  96.     MarginTop := 0.75;
  97.     SetFont('Arial',24);
  98.     Underline := true;
  99.     Home;
  100.     PrintCenter('Report Page Demo',PageWidth / 2);
  101.  
  102.     SetFont('Times New Roman',8);
  103.     MarginBottom := 0.25;
  104.     PrintFooter('Page ' + IntToStr(CurrentPage),pjLeft);
  105.     PrintFooter('Date 01/20/95',pjRight);
  106.     MarginBottom := 0.5;
  107.  
  108.     YPos := 1.5;
  109.     SetFont('Times New Roman',12);
  110.     SetTopOfPage;
  111.     Home;
  112.  
  113.   { Print column headers }
  114.     ClearTabs;
  115.     SetPen(clBlack,psSolid,1,pmCopy); { Set pen to 1 dot width }
  116.     SetTab(0.5,pjCenter,3.5,0,BOXLINEALL,0);
  117.     SetTab(NA,pjCenter,1.0,0,BOXLINEALL,0);
  118.     SetTab(NA,pjCenter,1.5,0,BOXLINEALL,0);
  119.     SetTab(NA,pjCenter,1.5,0,BOXLINEALL,0);
  120.     Bold := true;
  121.     Tab(-2,NA,-2,-2,NA); { Draw tab box with heavy outer borders }
  122.     Print('Name');
  123.     Tab(NA,NA,-2,-2,NA); { Draw tab box with heavy outer borders }
  124.     Print('Number');
  125.     Tab(NA,NA,-2,-2,NA); { Draw tab box with heavy outer borders }
  126.     Print('Amount 1');
  127.     Tab(NA,-2,-2,-2,NA); { Draw tab box with heavy outer borders }
  128.     Println('Amount 2');
  129.     Bold := false;
  130.  
  131.   { Print data lines in boxes }
  132.     ClearTabs;
  133.     SetTab(0.5,pjLeft,3.5,2,BOXLINEALL,0);
  134.     SetTab(NA,pjCenter,1.0,2,BOXLINEALL,0);
  135.     SetTab(NA,pjRight,1.5,2,BOXLINEALL,10);
  136.     SetTab(NA,pjRight,1.5,2,BOXLINEALL,0);
  137.     For I1 := 1 to 10 do begin
  138.       Str(I1 * 1.23:2:2,S1);
  139.       Str(I1 * 98.76:2:2,S2);
  140.       Print(#9'LastName' + IntToStr(I1) + ', ');
  141.       SetFont('Times New Roman',8);
  142.       Print('FirstName M.');
  143.       SetFont('Times New Roman',12);
  144.       Println(#9 + IntToStr(I1) + #9'$' + S1 + #9'$' + S2);
  145.     end; { for }
  146.  
  147.   { Print data lines with shading }
  148.     StatusText[1] := 'Graybar columns';
  149.     UpdateStatus;
  150.     ClearTabs;
  151.     SetTab(0.5,pjLeft,3.5,2,BOXLINENONE,0);
  152.     SetTab(NA,pjCenter,1.0,2,BOXLINENONE,0);
  153.     SetTab(NA,pjRight,1.5,2,BOXLINENONE,0);
  154.     SetTab(NA,pjRight,1.5,2,BOXLINENONE,0);
  155.     For I1 := 11 to 20 do begin
  156.       If Odd(I1) then begin
  157.         TabShade := 0;
  158.       end else begin
  159.         TabShade := 15;
  160.       end; { else }
  161.       Str(I1 * 1.23:2:2,S1);
  162.       Str(I1 * 98.76:2:2,S2);
  163.       Print(#9'LastName' + IntToStr(I1) + ', ');
  164.       SetFont('Times New Roman',8);
  165.       Print('FirstName M.');
  166.       SetFont('Times New Roman',12);
  167.       Println(#9 + IntToStr(I1) + #9'$' + S1 + #9'$' + S2);
  168.     end; { for }
  169.     ClearTabs;
  170.  
  171.   { Columns demo }
  172.     StatusText[1] := 'Columns of information';
  173.     UpdateStatus;
  174.     ClearTabs;
  175.     SetTopOfPage;
  176.     MarginBottom := 3.0;
  177.     Home;
  178.     SetFont('Times New Roman',12);
  179.     Bold := true;
  180.     Underline := true;
  181.     Italic := true;
  182.     Print('Columns (LinesLeft/ColumnLinesLeft/LineNum/ColumnNum)');
  183.     SetTopOfPage; { Set top of page to current YPos }
  184.     Bold := false;
  185.     Underline := false;
  186.     Italic := false;
  187.     Home; { Goto home position }
  188.  
  189.     SetColumns(4,0.5); { Create 4 columns with 0.5" between each }
  190.     While ColumnLinesLeft > 0 do begin
  191.       Println(IntToStr(LinesLeft) + '/' + IntToStr(ColumnLinesLeft) + '/' +
  192.        IntToStr(LineNum) + '/' + IntToStr(ColumnNum));
  193.     end; { while }
  194.  
  195.   { Columns demo }
  196.     StatusText[1] := 'Boxed Columns of information';
  197.     UpdateStatus;
  198.     ClearTabs;
  199.     SetTopOfPage;
  200.     MarginBottom := 0.5;
  201.     Home;
  202.     SetFont('Times New Roman',12);
  203.     Bold := true;
  204.     Italic := true;
  205.     Print('Boxed Columns');
  206.     SetTopOfPage; { Set top of page to current YPos }
  207.     Bold := false;
  208.     Italic := false;
  209.     Home; { Goto home position }
  210.  
  211.     SetColumns(4,0.5); { Create 4 columns with 0.5" between each }
  212.     ClearTabs;
  213.     SetPen(clBlack,psSolid,1,pmCopy); { Set pen to 1 dot width }
  214.     SetTab(0.5,pjCenter,0.375,0,BOXLINEALL,0);
  215.     SetTab(NA,pjCenter,0.375,0,BOXLINEALL,0);
  216.     SetTab(NA,pjCenter,0.375,0,BOXLINEALL,0);
  217.     SetTab(NA,pjCenter,0.375,0,BOXLINEALL,0);
  218.     While ColumnLinesLeft > 0 do begin
  219.       If LineNum = 1 then begin
  220.         TabShade := 15;
  221.         Println(#9'LL'#9'CLL'#9'L#'#9'C#'); { Print title bar }
  222.       end else begin
  223.         TabShade := 0;
  224.         Println(#9 + IntToStr(LinesLeft) + #9 + IntToStr(ColumnLinesLeft) +
  225.          #9 + IntToStr(LineNum) + #9 + IntToStr(ColumnNum));
  226.       end; { else }
  227.     end; { while }
  228.     SetColumns(1,0);
  229.  
  230.   {*** Graphics page demonstration ***}
  231.     NewPage;
  232.     MarginTop := 0.5;
  233.     MarginBottom := 0.5;
  234.     StatusText[0] := 'Printing Graphics Page';
  235.     UpdateStatus;
  236.     SetFont('Arial',24);
  237.     Underline := true;
  238.     Home;
  239.     PrintCenter('Graphics Page Demo',PageWidth / 2);
  240.     OriginX := 0.0;
  241.     OriginY := 0.5;
  242.     SetFont('Times New Roman',8);
  243.  
  244.     MarginBottom := 0.25; { Temporarily move the bottom margin down }
  245.     PrintFooter('Page ' + IntToStr(CurrentPage),pjLeft);
  246.     PrintFooter('Date 01/20/95',pjRight);
  247.     MarginBottom := 0.5; { Reset bottom margin }
  248.  
  249.     SetFont('Arial',10);
  250.  
  251.   { Arc/Chord demo }
  252.     StatusText[1] := 'GDI functions';
  253.     UpdateStatus;
  254.     SetPen(clBlack,psSolid,-2,pmCopy); { Set pen to black 2/100ths" wide }
  255.     YPos := 0.95;
  256.     PrintCenter('Arc() and Chord()',2.125);
  257.     Arc(1.125,1.0,3.125,3.0,3.125,2.0,0.0,0.0);
  258.     SetBrush(clBlack,bsClear,nil);
  259.     Chord(1.125,1.0,3.125,3.0,0.0,0.8,3.125,2.25);
  260.  
  261.   { Pie demo }
  262.     YPos := 0.95;
  263.     PrintCenter('Pie()',4.25);
  264.     SetPen(clBlack,psSolid,-2,pmCopy); { Set pen to black 2/100ths" wide }
  265.     SetBrush(clBlack,bsHorizontal,nil);
  266.     Pie(3.25,1.0,5.25,3.0,5.25,2.0,0.0,0.0);
  267.     SetBrush(clBlack,bsVertical,nil);
  268.     Pie(3.25,1.0,5.25,3.0,0.0,0.0,3.25,7.0);
  269.     SetBrush(clBlack,bsBDiagonal,nil);
  270.     Pie(3.25,1.0,5.25,3.0,3.25,7.0,5.25,2.0);
  271.  
  272.   { Ellipse demo }
  273.     YPos := 1.2;
  274.     PrintCenter('Ellipse()',6.375);
  275.     SetBrush(clBlack,bsCross,nil);
  276.     Ellipse(5.375,1.25,7.375,2.75);
  277.  
  278.   { RoundRect Demo }
  279.     YPos := 3.4;
  280.     PrintCenter('RoundRect()',2.125);
  281.     SetBrush(clBlack,bsDiagCross,nil);
  282.     RoundRect(1.125,3.5,3.125,5.0,0.25,0.25);
  283.     YPos := 4.0;
  284.     SetBrush(clBlack,bsSolid,nil);
  285.     TextBKMode := bkOpaque;
  286.     SetBKColor(Printer.Canvas.Handle,clWhite);
  287.     PrintCenter('Opaque Text',2.125);
  288.     YPos := 4.5;
  289.     TextBKMode := bkTransparent;
  290.     PrintCenter('Transparent Text',2.125);
  291.  
  292.   { Polyline demo }
  293.     YPos := 3.4;
  294.     PrintCenter('psDash w/ PolyLine()',4.25);
  295.     OriginX := 4.25; { Set origin for simpler calc }
  296.     OriginY := 5.0;
  297.     SetPen(clBlack,psDash,-2,pmCopy); { Set pen to black 2/100ths" wide }
  298.     PolyLineArr[1] := CreatePoint(0,-1);
  299.     PolyLineArr[2] := CreatePoint(-0.59,0.81);
  300.     PolyLineArr[3] := CreatePoint(0.95,-0.31);
  301.     PolyLineArr[4] := CreatePoint(-0.95,-0.31);
  302.     PolyLineArr[5] := CreatePoint(0.59,0.81);
  303.     PolyLineArr[6] := CreatePoint(0,-1);
  304.     PolyLine(PolyLineArr);
  305.     OriginX := 0.0; { Reset origin }
  306.     OriginY := 0.5;
  307.  
  308.   { PaintBitmap demo }
  309.     YPos := 3.4;
  310.     PrintCenter('PaintBitmapRect()',6.375);
  311.     Bitmap := TBitmap.Create;
  312.     Bitmap.LoadFromFile('D:\RPTEST\RPDEMO.BMP');
  313.     PrintBitmapRect(5.375,3.5,7.375,5.5,Bitmap);
  314.     Bitmap.Free;
  315.  
  316.   { Units demo }
  317.     StatusText[1] := 'Units demo';
  318.     UpdateStatus;
  319.     SetPen(clBlack,psSolid,-1,pmCopy); { Set pen to black 1/100ths" wide }
  320.     GotoXY(1.0,5.5);
  321.     Bold := true;
  322.     Underline := true;
  323.     Italic := true;
  324.     Print('Units Demonstration');
  325.     Bold := false;
  326.     Underline := false;
  327.     Italic := false;
  328.  
  329.   { Draw inches ruler }
  330.     Units := unInch;
  331.     GotoXY(1.0,5.75);
  332.     Bold := true;
  333.     Print('Inches');
  334.     Bold := false;
  335.     YPos := 6.0;
  336.     MoveTo(1.0,6.25);
  337.     LineTo(7.0,6.25);
  338.     For I1 := 0 to 6 do begin
  339.       PrintCenter(IntToStr(I1),I1 + 1);
  340.       MoveTo(I1 + 1,6.05);
  341.       LineTo(I1 + 1,6.25);
  342.     end; { for }
  343.  
  344.   { Draw millimeters ruler }
  345.     Units := unMM;
  346.     OriginY := 12.7; { Set to 1/2 inch down }
  347.     GotoXY(25.4,170);
  348.     Bold := true;
  349.     Print('Millimeters');
  350.     Bold := false;
  351.     YPos := 175;
  352.     MoveTo(25.4,180);
  353.     LineTo(175.4,180);
  354.     For I1 := 0 to 15 do begin
  355.       PrintCenter(IntToStr(I1 * 10),I1 * 10 + 25.4);
  356.       MoveTo(I1 * 10 + 25.4,176);
  357.       LineTo(I1 * 10 + 25.4,180);
  358.     end; { for }
  359.     Units := unInch; { Set units back to inches }
  360.  
  361.   { Text at specific locations }
  362.     StatusText[1] := 'Text at specific locations';
  363.     UpdateStatus;
  364.     OriginX := 0.0; { Set origin to normal }
  365.     OriginY := 0.0;
  366.     GotoXY(1.0,8.5);
  367.     Print('Text @ 1.0,8.5');
  368.     GotoXY(6.0,8.5);
  369.     Println('Text @ 6.0,8.5');
  370.     GotoXY(2.0,9.0);
  371.     Println('Text @ 2.0,9.0');
  372.     GotoXY(3.0,9.5);
  373.     Println('Text @ 3.0,9.5');
  374.   end; { with }
  375. end;
  376.  
  377. end.
  378.